package com.slipper.bpmn.parser.support;

import com.slipper.bpmn.parser.IParser;
import org.dom4j.Element;

import com.slipper.bpmn.model.TaskNode;

public class TaskNodeParser implements IParser<TaskNode> {
    @Override
    public TaskNode parser(Element element) {
        TaskNode taskNode = parser(new TaskNode(), element);
        taskNode.setCanBack(element.attributeValue("canBack"));
        taskNode.setBeCanBack(element.attributeValue("canBeBack"));
        taskNode.setCanStop(element.attributeValue("canStop"));
        taskNode.setSignatureType(element.attributeValue("signatureType"));
        taskNode.setModelId(element.attributeValue("modelId"));
        taskNode.setTitleFieldName(element.attributeValue("titleFieldName"));
        taskNode.setEditPageId(element.attributeValue("editPageId"));
        taskNode.setEditPageDataParamId(element.attributeValue("editPageDataParamId"));
        taskNode.setViewPageId(element.attributeValue("viewPageId"));
        taskNode.setViewPageDataParamId(element.attributeValue("viewPageDataParamId"));
        taskNode.setMessageType(element.attributeValue("messageType"));
        taskNode.setMessageTpl(element.attributeValue("messageTpl"));
        taskNode.setCanSubFlow(element.attributeValue("canSubFlow"));
        taskNode.setSubFlowId(element.attributeValue("subFlowId"));
        taskNode.setSubFlowParam(element.attributeValue("subFlowParam"));
        taskNode.setScriptId(element.attributeValue("scriptId"));
        taskNode.setRemark(element.attributeValue("remark"));

        if (taskNode.getInLine().isEmpty()) {
            throw new RuntimeException("人工节点[" + taskNode.getName() + "]必须至少有一条流入线！");
        }

        if (taskNode.getOutLine().isEmpty()) {
            throw new RuntimeException("人工节点[" + taskNode.getName() + "]必须至少有一条流出线！");
        }

        return taskNode;
    }
}
